<html>
<body>
<div>dummy</div>
<script type='text/javascript'>
window.addEventListener('load',
	function() {
		with (document) {
			var pool = getElementById('POOL').textContent;
			open();
			write(pool);
			close();
		}
	}, false);
</script>
<noscript id='POOL' style='display:none;'>

<div id='space'></div>
<script>

var MAX_LV = 3;
var MAX_LV_KING = 3;

var POW_BASE = 3;
var POW_KING = 2;

var cNode = function(in_x, in_y, in_group, in_is_king)
{
	this._x = in_x;
	this._y = in_y;
	this._group = in_group.g;
	this._direction = in_group.d;
	this._level = 1;
	this._isKing = in_is_king;
};

cNode.prototype = {
	__dirtbl : [
		/*
			x : 0, 2, 4, ...

			+-+     +-+
			|*|     |*|
			+-+ +-+ +-+ +-+
			    | |     | |
			+-+ +-+ +-+ +-+
			|*|     |*|
			+-+ +-+ +-+ +-+
			    | |     | |
			    +-+     +-+
		*/
		{
			u  : {dx :  0, dy : -1},
			ru : {dx :  1, dy : -1},
			rd : {dx :  1, dy :  0},
			d  : {dx :  0, dy :  1},
			ld : {dx : -1, dy :  0},
			lu : {dx : -1, dy : -1}
		},
		/*
			x : 1, 3, 5, ...

			+-+     +-+
			| |     | |
			+-+ +-+ +-+ +-+
			    |*|     |*|
			+-+ +-+ +-+ +-+
 			| |     | |
			+-+ +-+ +-+ +-+
			    |*|     |*|
			    +-+     +-+
		*/
		{
			u  : {dx :  0, dy : -1},
			ru : {dx :  1, dy :  0},
			rd : {dx :  1, dy :  1},
			d  : {dx :  0, dy :  1},
			ld : {dx : -1, dy :  1},
			lu : {dx : -1, dy :  0}
		}
	],
	_dirtbl : function() {
		return this.__dirtbl[(this._x % 2)];
	},
	levelUp : function() {
		if (this._level < (this._isKing ? MAX_LV_KING : MAX_LV)) {
			this._level++;
		}
		return this._level;
	},
	percent : function() {
		var l2p = [50, 60, 70, 80, 90];
		return l2p[this._level];
	},
	_testImgSrc : {
		'img/G_R-u-1.png'   : 'img/tmp/r-u-1.png',
		'img/G_R-ru-1.png'  : 'img/tmp/r-r-1.png',
		'img/G_R-rd-1.png'  : 'img/tmp/r-r-1.png',
		'img/G_R-d-1.png'   : 'img/tmp/r-d-1.png',
		'img/G_R-ld-1.png'  : 'img/tmp/r-l-1.png',
		'img/G_R-lu-1.png'  : 'img/tmp/r-l-1.png',
		'img/G_R-u-2.png'   : 'img/tmp/r-u-1.png',
		'img/G_R-ru-2.png'  : 'img/tmp/r-r-1.png',
		'img/G_R-rd-2.png'  : 'img/tmp/r-r-1.png',
		'img/G_R-d-2.png'   : 'img/tmp/r-d-1.png',
		'img/G_R-ld-2.png'  : 'img/tmp/r-l-1.png',
		'img/G_R-lu-2.png'  : 'img/tmp/r-l-1.png',
		'img/G_R-u-3.png'   : 'img/tmp/r-u-1.png',
		'img/G_R-ru-3.png'  : 'img/tmp/r-r-1.png',
		'img/G_R-rd-3.png'  : 'img/tmp/r-r-1.png',
		'img/G_R-d-3.png'   : 'img/tmp/r-d-1.png',
		'img/G_R-ld-3.png'  : 'img/tmp/r-l-1.png',
		'img/G_R-lu-3.png'  : 'img/tmp/r-l-1.png',

		'img/G_RK-u-1.png'  : 'img/tmp/r-u-1.png',
		'img/G_RK-ru-1.png' : 'img/tmp/r-r-1.png',
		'img/G_RK-rd-1.png' : 'img/tmp/r-r-1.png',
		'img/G_RK-d-1.png'  : 'img/tmp/r-d-1.png',
		'img/G_RK-ld-1.png' : 'img/tmp/r-l-1.png',
		'img/G_RK-lu-1.png' : 'img/tmp/r-l-1.png',
		'img/G_RK-u-2.png'  : 'img/tmp/r-u-1.png',
		'img/G_RK-ru-2.png' : 'img/tmp/r-r-1.png',
		'img/G_RK-rd-2.png' : 'img/tmp/r-r-1.png',
		'img/G_RK-d-2.png'  : 'img/tmp/r-d-1.png',
		'img/G_RK-ld-2.png' : 'img/tmp/r-l-1.png',
		'img/G_RK-lu-2.png' : 'img/tmp/r-l-1.png',
		'img/G_RK-u-3.png'  : 'img/tmp/r-u-1.png',
		'img/G_RK-ru-3.png' : 'img/tmp/r-r-1.png',
		'img/G_RK-rd-3.png' : 'img/tmp/r-r-1.png',
		'img/G_RK-d-3.png'  : 'img/tmp/r-d-1.png',
		'img/G_RK-ld-3.png' : 'img/tmp/r-l-1.png',
		'img/G_RK-lu-3.png' : 'img/tmp/r-l-1.png',

		'img/G_B-u-1.png'   : 'img/tmp/b-u-1.png',
		'img/G_B-ru-1.png'  : 'img/tmp/b-r-1.png',
		'img/G_B-rd-1.png'  : 'img/tmp/b-r-1.png',
		'img/G_B-d-1.png'   : 'img/tmp/b-d-1.png',
		'img/G_B-ld-1.png'  : 'img/tmp/b-l-1.png',
		'img/G_B-lu-1.png'  : 'img/tmp/b-l-1.png',
		'img/G_B-u-2.png'   : 'img/tmp/b-u-1.png',
		'img/G_B-ru-2.png'  : 'img/tmp/b-r-1.png',
		'img/G_B-rd-2.png'  : 'img/tmp/b-r-1.png',
		'img/G_B-d-2.png'   : 'img/tmp/b-d-1.png',
		'img/G_B-ld-2.png'  : 'img/tmp/b-l-1.png',
		'img/G_B-lu-2.png'  : 'img/tmp/b-l-1.png',
		'img/G_B-u-3.png'   : 'img/tmp/b-u-1.png',
		'img/G_B-ru-3.png'  : 'img/tmp/b-r-1.png',
		'img/G_B-rd-3.png'  : 'img/tmp/b-r-1.png',
		'img/G_B-d-3.png'   : 'img/tmp/b-d-1.png',
		'img/G_B-ld-3.png'  : 'img/tmp/b-l-1.png',
		'img/G_B-lu-3.png'  : 'img/tmp/b-l-1.png',

		'img/G_BK-u-1.png'  : 'img/tmp/b-u-1.png',
		'img/G_BK-ru-1.png' : 'img/tmp/b-r-1.png',
		'img/G_BK-rd-1.png' : 'img/tmp/b-r-1.png',
		'img/G_BK-d-1.png'  : 'img/tmp/b-d-1.png',
		'img/G_BK-ld-1.png' : 'img/tmp/b-l-1.png',
		'img/G_BK-lu-1.png' : 'img/tmp/b-l-1.png',
		'img/G_BK-u-2.png'  : 'img/tmp/b-u-1.png',
		'img/G_BK-ru-2.png' : 'img/tmp/b-r-1.png',
		'img/G_BK-rd-2.png' : 'img/tmp/b-r-1.png',
		'img/G_BK-d-2.png'  : 'img/tmp/b-d-1.png',
		'img/G_BK-ld-2.png' : 'img/tmp/b-l-1.png',
		'img/G_BK-lu-2.png' : 'img/tmp/b-l-1.png',
		'img/G_BK-u-3.png'  : 'img/tmp/b-u-1.png',
		'img/G_BK-ru-3.png' : 'img/tmp/b-r-1.png',
		'img/G_BK-rd-3.png' : 'img/tmp/b-r-1.png',
		'img/G_BK-d-3.png'  : 'img/tmp/b-d-1.png',
		'img/G_BK-ld-3.png' : 'img/tmp/b-l-1.png',
		'img/G_BK-lu-3.png' : 'img/tmp/b-l-1.png'
	},
	getImgSrc : function() {
		if (arguments.length == 2) {
			var dir = this.xy2dir(arguments[0], arguments[1]);
		} else {
			var dir = this._direction;
		}
		if (this._isKing) {
			var src = this._group + 'K';
		} else {
			var src = this._group;
		}
		src = 'img/' + src + '-' + dir + '-' + this._level + '.png';
		return this._testImgSrc[src];
	},
	isEnemy : function(in_node) {
		return (this._group != in_node._group);
	},
	arroundxy : function() {
		/*
			returns [x, y] * 6
		*/
		var ret = [];
		for (var dir in this._dirtbl()) {
			ret.push(this.dir2xy(dir));
		}
		return ret;
	},
	dir2xy : function(in_dir) {
		var d = this._dirtbl()[in_dir];
		return [this._x + d.dx, this._y + d.dy];
	},
	xy2dir : function(in_x, in_y) {
		/*
			returns null : node is not arround 
		*/
		var dx = in_x - this._x;
		var dy = in_y - this._y;
		for (var dir in this._dirtbl()) {
			d = this._dirtbl()[dir];
			if ((d.dx == dx) && (d.dy == dy)) {
				return dir;
			}
		}
		return null;
	},
	node2dir : function(in_node) {
		return this.xy2dir(in_node._x, in_node._y);
	},
	pow : function() {
		return POW_BASE + (this._isKing ? POW_KING : 0) + this._level;
	},
	_attack : function(in_node, in_rand) {
		var cnt = 0;
		var target = this.node2dir(in_node);
		for (dir in this._dirtbl()) {
			if (dir == target) {
				var v1 = cnt;
			}
			if (dir == in_node._direction) {
				var v2 = cnt;
			}
			cnt++;
		}
		var enemy_pow = 0;
		switch (Math.abs(v1 - v2)) {
		case 3 :
			enemy_pow = 100;
			break;
		case 2 :
		case 4 :
			enemy_pow = 75;
			break;
		case 1 :
		case 5 :
			enemy_pow = 50;
			break;
		case 0 :
		default :
			enemy_pow = 25;
			break;
		}
		// alert('self : ' + this.pow() + ', enemy : ' + in_node.pow() + ' * ' + enemy_pow + ' / 100');
		if (in_rand) {
			return Math.random() * this.pow() - Math.random() * (in_node.pow() * enemy_pow / 100);
		} else {
			return this.pow() - (in_node.pow() * enemy_pow / 100);
		}
	},
	attack : function(in_node) {
		/*
			returns  1 : win
			returns  0 : node is not arround / node is not enemy
			returns -1 : lose
		*/
		var dir = this.node2dir(in_node);
		if (!dir) {
			return 0;
		}
		if (!this.isEnemy(in_node)) {
			return 0;
		}
		return ((this._attack(in_node, true) > 0) ? 1 : -1);
	},
	dp : function() {
		if ((typeof this.dp_cnt) == 'undefined') {
			this.dp_cnt = 0;
		}
		if (this.dp_cnt++ < 10) {
			var data = "(x, y) = (" + this._x + ", " + this._y + ")\n";
			data += "group = " + this._group + "\n";
			data += "direction = " + this._direction + "\n";
			data += "level = " + this._level + "\n";
			if (this._isKing) {
				data += "[KING]\n";
			}
			alert(data);
		}
	}
};

function ut_node()
{
	// levelUp()
	var n1 = new cNode(0, 0, {g : 'G_B', d : 'u'}, false);
	if (n1.levelUp() != 2) {
		alert('NG-01');
	}
	if (n1.levelUp() != 3) {
		alert('NG-02');
	}
	if (n1.levelUp() != 3) {
		alert('NG-03');
	}
	var n1 = new cNode(0, 0, {g : 'G_B', d : 'u'}, true);
	if (n1.levelUp() != 2) {
		alert('NG-04');
	}
	if (n1.levelUp() != 3) {
		alert('NG-05');
	}
	if (n1.levelUp() != 4) {
		alert('NG-06');
	}
	if (n1.levelUp() != 5) {
		alert('NG-07');
	}
	if (n1.levelUp() != 5) {
		alert('NG-08');
	}
	// isEnemy()
	var n2 = new cNode(0, 1, {g : 'G_R', d : 'd'}, false);
	if (!n1.isEnemy(n2)) {
		alert('NG-09');
	}
	var n2 = new cNode(0, 1, {g : 'G_B', d : 'd'}, false);
	if (n1.isEnemy(n2)) {
		alert('NG-10');
	}
	// arroundxy() & attack() #1
	var X = 3;
	var Y = 3;
	var T = [/*[X-1, Y-1],*/ [X, Y-1], /*[X+1, Y-1],*/ [X-1, Y], [X+1, Y], [X-1, Y+1], [X, Y+1], [X+1, Y+1]];
	var n1 = new cNode(X, Y, {g : 'G_B', d : 'u'}, true);
	var a = n1.arroundxy();
	for (var i in T) {
		var ret = (function(in_a, in_xy){
			for (var i = 0; i < in_a.length; i++) {
				if ((in_a[i][0] == in_xy[0]) && (in_a[i][1] == in_xy[1])) {
					return true;
				}
			}
			return false;
		})(a, T[i]);
		if (!ret) {
			alert('NG-11-1');
		}
	}
	var n = new cNode(X, Y, {g : 'G_B', d : 'u'}, false);
	var e = [];
	var s = [];
	for (var i = 0; i < T.length; i++) {
		e[i] = new cNode(T[i][0], T[i][1], {g : 'G_R',  d : 'd'}, false);
		s[i] = 0;
	}
	for (var i = 0; i < 1000; i++) {
		for (var j = 0; j < T.length; j++) {
			(n._attack(e[j], true) > 0) ? s[j]++ : null;
		}
	}
	// alert(s.join(','));
	if ((s[0] > s[1]) || (s[1] > s[3]) || (s[3] > s[4])) {
		alert('NG-11-2');
	}
	// arroundxy() & attack() #2
	var X = 4;
	var Y = 3;
	var T = [[X-1, Y-1], [X, Y-1], [X+1, Y-1], [X-1, Y], [X+1, Y], /*[X-1, Y+1],*/ [X, Y+1]/*, [X+1, Y+1]*/];
	var n1 = new cNode(X, Y, {g : 'G_B', d : 'u'}, true);
	var a = n1.arroundxy();
	for (var i in T) {
		var ret = (function(in_a, in_xy){
			for (var i = 0; i < in_a.length; i++) {
				if ((in_a[i][0] == in_xy[0]) && (in_a[i][1] == in_xy[1])) {
					return true;
				}
			}
			return false;
		})(a, T[i]);
		if (!ret) {
			alert('NG-12-1');
		}
	}
	var n = new cNode(X, Y, {g : 'G_B', d : 'u'}, false);
	var e = [];
	var s = [];
	for (var i = 0; i < T.length; i++) {
		e[i] = new cNode(T[i][0], T[i][1], {g : 'G_R',  d : 'd'}, false);
		s[i] = 0;
	}
	for (var i = 0; i < 1000; i++) {
		for (var j = 0; j < T.length; j++) {
			(n._attack(e[j], true) > 0) ? s[j]++ : null;
		}
	}
	// alert(s.join(','));
	if ((s[1] > s[0]) || (s[0] > s[3]) || (s[3] > s[5])) {
		alert('NG-12-2');
	}
	alert('OK');
}

//ut_node();

var MAPDATA = {
	_dat : [
		{
			title : '1st map',
			clear : false,
			players : [
				{group : 'G_R', dir : 'd'},
				{group : 'G_B', dir : 'u'}
			],
			w : 5,
			h : 5,
			s : [
				-1, 0,21, 0,-1,
				 0, 0,26, 0, 0,
				 0, 0,-1, 0, 0,
				 0, 0,17, 0, 0,
				-1,-1,12,-1,-1
			]
		},
		{
			title : '2nd map',
			clear : false,
			players : [
				{group : 'G_R', dir : 'd'},
				{group : 'G_B', dir : 'u'}
			],
			w : 9,
			h : 9,
			s : [
				0, 0, 0, 0, 0, 0, 0, 0, 0,
				0, 0, 0, 0,26, 0, 0, 0, 0,
				0, 0, 0, 0,21, 0, 0, 0, 0,
				0, 0, 0, 0, 0, 0, 0, 0, 0,
				0, 0,21, 0, 0, 0,11, 0, 0,
				0, 0, 0, 0, 0, 0, 0, 0, 0,
				0, 0, 0, 0,11, 0, 0, 0, 0,
				0, 0, 0, 0,16, 0, 0, 0, 0,
				0,-1, 0,-1, 0,-1, 0,-1, 0
			]
		}
	],
	_g2n : {
		HOLE : -1,
		EMPTY : 0,
		G_B : 1,
		G_R : 2,
		G_G : 3,
		UNKNOWN : 99
	},
	n2g : function(in_n) {
		for (var group in this._g2n) {
			if (in_n == this._g2n[group]) {
				break;
			}
		}
		return group;
	},
	initNode : function(in_x, in_y, in_dat) {
		var src = in_dat.s[(in_y * in_dat.w) + in_x];
		var group = this.n2g(src);
		if (group == 'UNKNOWN') {
			var d10 = Math.floor(src / 10);
			group = this.n2g(d10);
			for (var i = 0; i < in_dat.players.length; i++) {
				if (in_dat.players[i].group == group) {
					var dir = in_dat.players[i].dir;
					break;
				}
			}
			var level = src - d10 * 10
			var isKing = (level >= 5);
			if (isKing) {
				level = level - 5;
			}
			var node = new cNode(in_x, in_y, {g : group, d : dir}, isKing);
			while (--level > 0) {
				node.levelUp();
			}
		} else {
			var node = null;
		}
		return {group : group, node : node};
	}
};

var HIT_INTERVAL = 25;
var HIT_REPEAT = 10;

function hit_animation(in_div, in_cnt, in_repeat, in_interval)
{
	in_div.setImg('img/hit.png', 100 - (100 / in_repeat) * in_cnt / 2);
}

var BATTLE_INTERVAL = 50;
var BATTLE_REPEAT = 10;

function battle_animation(in_div, in_cnt, in_repeat, in_interval, in_rem)
{
	if ((in_cnt % 2) == in_rem) {
		in_div.colorFocus();
	} else {
		in_div.colorNormal();
	}
}

function battle_animation1(in_div, in_cnt, in_repeat, in_interval)
{
	battle_animation(in_div, in_cnt, in_repeat, in_interval, 0);
}

function battle_animation2(in_div, in_cnt, in_repeat, in_interval)
{
	battle_animation(in_div, in_cnt, in_repeat, in_interval, 1);
}

var CELL_W = 52;
var CELL_H = 48;
var CELL_M = 8;

function map_xy2px(in_x, in_y)
{
	var px = {
		x : CELL_M + (CELL_W + CELL_M) * in_x,
		y : CELL_M + (CELL_H + CELL_M) * in_y
	};
	if ((in_x % 2) == 1) {
		px.y += (CELL_H + CELL_M) / 2;
	}
	px.x += 'px';
	px.y += 'px';
	return px;
}

var DIV_EXTENSION = {
	initCell : function(in_x, in_y) {
		var px = map_xy2px(in_x, in_y);
		with (this.style) {
			position = 'absolute';
			left = px.x;
			top = px.y;
			width = CELL_W + 'px';
			height = CELL_H + 'px';
		}
		this.colorNormal();
	},
	animation : function(in_repeat, in_interval, in_snapshot, in_finish) {
		var cnt = 0;
		var self = this;
		var delta = (function() {
			return function() {
				if (cnt++ < in_repeat) {
					in_snapshot(self, cnt, in_repeat, in_interval);
					window.setTimeout(delta, in_interval);
				} else {
					if (in_finish) {
						in_finish();
					}
				}
			};
		})();
		delta();
	},
	setImg : function(in_src, in_percent) {
		var imgs = this.getElementsByTagName('IMG');
		if (imgs.length > 0) {
			var img = imgs.item(0);
		} else {
			var img = document.createElement('IMG');
			this.appendChild(img);
		}
		img.src = in_src;
		with (img.style) {
			position = 'relative';
			left = ((100 - in_percent) / 2) + '%';
			top = ((100 - in_percent) / 2) + '%';
			width = in_percent + '%';
			height = in_percent + '%';
		}
	},
	color : function(in_bg, in_border) {
		with (this.style) {
			backgroundColor = in_bg;
			border = 'solid 1px ' + in_border;
			borderRadius = '4px';
		}
	},
	colorNormal : function() {
		this.color('silver', 'gray');
	},
	colorFocus : function() {
		this.color('yellow', 'silver');
	},
	colorDark : function() {
		this.color('gray', 'black');
	}
};

for (prop in DIV_EXTENSION) {
	HTMLDivElement.prototype[prop] = DIV_EXTENSION[prop];
}

var gMap = {
	_diabled : true,
	_curMap : 0,
	_pos : [],
	_w : 0,
	_h : 0,
	stageInit : function() {
		for (var i = 0; i < MAPDATA._dat.length; i++) {
			if (!MAPDATA._dat[i].clear) {
				this._curMap = i;
				break;
			}
		}
		var dat = MAPDATA._dat[this._curMap];
		this._w = dat.w;
		this._h = dat.h;
		for (var x = 0; x < this._w; x++) {
			this._pos[x] = [];
			for (var y = 0; y < this._h; y++) {
				var init = MAPDATA.initNode(x, y, dat);
				if (init.group == 'HOLE') {
					var div = null;
				} else {
					var div = document.createElement('DIV');
					div.initCell(x, y);
					div.onclick = (function(in_x, in_y){return function(){
						gMap.userEvent(in_x, in_y);
					};})(x, y);
					document.getElementById('space').appendChild(div);
					if (init.group != 'EMPTY') {
						div.setImg(init.node.getImgSrc(), init.node.percent());
					}
				}
				this._pos[x][y] = {
					/*
						group : G_X, HOLE, EMPTY
					*/
					group : init.group,
					/*
						node : G_X
						null : HOLE, EMPTY
					*/
					node : init.node,
					/*
						div : G_X, EMPTY
						null : HOLE
					*/
					div : div
				};
			}
		}
		this._diabled = false;
	},
	computer : function() {
		for (var x = 0; x < gMap._w; x++) {
			for (var y = 0; y < gMap._h; y++) {
				var p = gMap._pos[x][y];
				if ((p.group == 'G_B') && (p.node._isKing)) {
					var target_x = x;
					var target_y = y;
				}
			}
		}
		var candidate_x = 0;
		var candidate_y = 0;
		for (var x = 0; x < gMap._w; x++) {
			for (var y = 0; y < gMap._h; y++) {
				var p = gMap._pos[x][y];
				if (p.group == 'G_R') {
					if (Math.abs(target_y - y) < Math.abs(target_y - candidate_y)) {
						candidate_x = x;
						candidate_y = y;
					} else {
						if (Math.abs(target_x - x) < Math.abs(target_x - candidate_x)) {
							candidate_x = x;
							candidate_y = y;
						}
					}
				}
			}
		}
		gMap.select(candidate_x, candidate_y, function(){gMap._diabled = false;});
	},
	userEvent : function(in_x, in_y) {
		if (this._diabled) {
			return;
		}
		if (this._pos[in_x][in_y].group != 'G_B') {
			return;
		}
		this._diabled = true;
		this.select(in_x, in_y, this.computer);
	},
	select : function(x1, y1, in_callback) {
		var pos = this._pos;
		var p1 = pos[x1][y1];
		if (!p1.node) {
			return;
		}
		var xy = p1.node.arroundxy();
		var targets = [];
		for (var i = 0; i < xy.length; i++) {
			// (1) on the map ?
			if ((xy[i][0] < 0) || (this._w - 1 < xy[i][0])) {
				continue;
			}
			if ((xy[i][1] < 0) || (this._h - 1 < xy[i][1])) {
				continue;
			}
			var p = pos[xy[i][0]][xy[i][1]];
			// (2) HOLE ?
			if (p.group == 'HOLE') {
				continue;
			}
			// (3) the same group ?
			if (p.group == p1.node._group) {
				continue;
			}
			targets.push(xy[i]);
		}
		var occupation = (function(){return function(x1, y1, x2, y2){
			// (x1, y1) ---> (x2, y2)
			var game_over = false;
			var p1 = pos[x1][y1];
			var p2 = pos[x2][y2];
			p2.group = p1.node._group;
			if (p2.node && p2.node._isKing ) {
				game_over = true;
			}
			p2.node = new cNode(x2, y2, {g : p1.node._group, d : p1.node._direction}, false);
			p2.div.setImg(p2.node.getImgSrc(), p2.node.percent());
			return game_over;
		};})();
		var repeat = (function() {
			return function() {
				var target = targets.pop();
				if (target) {
					var x2 = target[0];
					var y2 = target[1];
					// (1) change p1.node direction
					p1.div.setImg(p1.node.getImgSrc(x2, y2), p1.node.percent());
					var p2 = pos[x2][y2];
					if (p2.group == 'EMPTY') {
						// (2-1) get empty-field
						var cb = (function(){return function(){
							occupation(x1, y1, x2, y2);
							repeat();
						};})();
						p2.div.animation(
							HIT_REPEAT,
							HIT_INTERVAL,
							hit_animation,
							cb);
					} else {
						// (2-2) battle
						var cb = (function(){return function(){
							p1.div.colorNormal();
							p2.div.colorNormal();
							if (p1.node.attack(p2.node) > 0) {
								// (3-1) p1.node win
								var cb = (function(){return function(){
									if (occupation(x1, y1, x2, y2)) {
										alert('game over');
									} else {
										repeat();
									}
								};})();
								p2.div.animation(
									HIT_REPEAT,
									HIT_INTERVAL,
									hit_animation,
									cb);
							} else {
								// (3-2) p2.node win
								var cb = (function(){return function(){
									if (occupation(x2, y2, x1, y1)) {
										alert('game over');
									} else {
										// next player
										in_callback();
									}
								};})();
								p1.div.animation(
									HIT_REPEAT,
									HIT_INTERVAL,
									hit_animation,
									cb);
							}
						};})();
						p1.div.animation(
							BATTLE_REPEAT,
							BATTLE_INTERVAL,
							battle_animation1,
							cb);
						p2.div.animation(
							BATTLE_REPEAT,
							BATTLE_INTERVAL,
							battle_animation2,
							null);
					}
				} else {
					p1.node.levelUp();
					p1.div.setImg(p1.node.getImgSrc(), p1.node.percent());
					// next player
					in_callback();
				}
			};
		})();
		repeat();
	},
};

gMap.stageInit();

var gTurn = {
	_players : 0,
	_current : 0,
	setPlayer : function(in_n) {
		this._players = in_n;
	},
	next : function() {
		if (this._current == (this._players - 1)) {
			return 0;
		} else {
			return this._current++;
		}
	},
};

</script>

</noscript>
</body>
</html>
